using System;
using NUnit.Framework;

namespace Iowa.Infrastructure.Test.Test_PersonRepository
{
  public class Test_People_Base
  {
    protected int EntityId;
    protected Core.Models.Person Person;

    [SetUp]
    public void CreatePerson()
    {
      Person = new Core.Models.Person
        {
          Firstname = "Clark",
          Surname = "Kent",
          Organisation = "Planet",
          Nationality = "American",
          DateOfBirth = new DateTime(1987, 5, 14)
        };
    }

    protected int InsertPerson()
    {
      var repo = new PersonRepository();
      var result = repo.AddPerson(Person);
      EntityId = Person.Id;
      return result;
    }

    [TearDown]
    public void RemoveEntity()
    {
      if (EntityId == default(int))
        return;
      using (var context = new IowaDbEntities())
      {
        var entity = context.People.Find(EntityId);
        context.People.Remove(entity);
        context.SaveChanges();
      }
    }
  }
}
